<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <title></title>
  <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
  <meta name=ProgId content=VisualStudio.HTML>
  <meta name=Originator content="Microsoft Visual Studio .NET 7.1">
  <script src="../Script/util.js"></script>
  <script src="../Script/xmlutil.js"></script>
  <script src="../Script/prototype.js"></script>
  <script>

function doAdd(){ 
    userForm.action_.value = "add" ;
    
    $('format_').value = "xml" ;
    
    var form = $('userForm');
    var url = form.action ; 
    var myAjax = new Ajax.Request(url,
                                  {method:'post', 
                                   parameters: Form.serialize(form), 
                                   onComplete:onAdd,
                                   onLoading:showLoading}); 
} 

function onAdd(originalRequest){
 
    alert(originalRequest.responseText); 

}  

function doLogin(){ 
    userForm.action_.value = "login" ;
    
    if ($('format_').value == "xml") {
        $('format_').value = "" ;
    } else {
        $('format_').value = "xml" ;
    }
    
    var form = $('userForm');
    var url = form.action ; 
    var myAjax = new Ajax.Request(url,
                                  {method:'post', 
                                   parameters: Form.serialize(form), 
                                   onComplete:onLogin,
                                   onLoading:showLoading,
                                   onException:showException}); 
} 

function showException(e) {debugger;
    alert(e) ;
}

function showLoading() {
    loadingDiv.innerText = "loading..." + userForm.format_.value ;
}

function onLogin(originalRequest){
 
    alert(originalRequest.responseText); 
    //debugger;
    var result = xml2Object(originalRequest.responseText) ;
    
    if (result.code.innerText != '0') {
        alert(result.message.innerText) ;
    } else {
        if ($('format_').value == "xml") {
            fillTable(result) ;
        } else {
			var tableHTML = result.tableDiv.innerText ;
			alert( tableHTML) ;
			messageDiv.innerHTML = tableHTML ;
	    }
    }

    loadingDiv.innerText = "" ;
}  

function fillTable(obj) {
    removeTableRows();
    var tr = messageTable.insertRow() ;
    var rowObjs =  arrayParse(obj.dataSet) ;

    for(var i = 0;i<=rowObjs.length;i++) {rowObjs[i].from_.innerText;
        tr = messageTable.insertRow();
        td = tr.insertCell();
        td.innerText = rowObjs[i].message_id.innerText ;
        td = tr.insertCell();
        td.innerText = rowObjs[i].content_.innerText + (typeof(rowObjs[i].from_)!="undefined"?rowObjs[i].from_.innerText:"");
    }
}

function removeTableRows() {
    for (var i = messageTable.rows.length - 1 ; i > 0  ; i --) {
        messageTable.deleteRow(i);
    }
}
  </script>
</head>
<body>

<form action="/CMS/system/user.aspx" name="userForm">
  <input type="hidden" name="action_" value="login"/>
  <input type="hidden" name="format_" value="" />
  <table width="100%">
    <tr>
      <td>user:</td>
      <td><input type="text" name="system_user.login_id"/></td>
    </tr>
    <tr>
      <td>password:</td>
      <td><input type="password" name="system_user.password_"/></td>
    </tr>
    <tr>
      <td colspan="2" align="center">
        <table width="100%">
          <tr>
            <td>content</td>
            <td>from</td>
          </tr>
          <tr>
            <td><input type="text" name="user_message.content_"/></td>
            <td><input type="text" name="user_message.from_"/></td>
          </tr>
          <tr>
            <td><input type="text" name="user_message.content_" /></td>
            <td><input type="text" name="user_message.from_" /></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td colspan="2" align="center">
        <input type="button" name="submit" value="login" onclick="doLogin()" ID="Button1"/>
        <input type="button" name="submit" value="new" onclick="doAdd()" ID="Button2"/>
      </td>
    </tr>
    <tr>
      <td colspan="2" align="center"><div id="loadingDiv"></div></td>
    </tr>
    <tr>
      <td colspan="2" align="center">HTML Table</td>
    </tr>
    <tr>
      <td colspan="2" align="center"><span id="messageDiv"></span></td>
    </tr>
    <tr>
      <td colspan="2" align="center">XML Table</td>
    </tr>
    <tr>
      <td colspan="2" align="center">
        <table id="messageTable">
          <tr>
            <td>id</td>
            <td>content</td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  
</form>

</body>
</html>
